@extends('layout.master')

@section('title','帖子列表')

@section('css')
    @parent
    <!-- Daterange picker plugins css -->
    <link href="{{ asset('plugins/bower_components/bootstrap-daterangepicker/daterangepicker.css') }}" rel="stylesheet">
@endsection
@section('main')

	
    <div class="modal fade" id="btn-zhiding" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel1">置顶</h4>
                </div>
                <div class="modal-body">
                    <form class="floating-labels role-edit">
                        <input id="id-zhiding" name="id-zhiding" type="hidden" value="">
                        <fieldset style="border:0;">

                            <div class="form-group m-b-40 m-t-10">
                                <input type="text" class="form-control" id="zhiding-modify"  placeholder="请输入标题"  name="title" required><span class="highlight"></span> <span class="bar"></span>

                            </div>
                            <div class="form-actions">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="row">
                                            <div class="col-md-offset-3 col-md-9">
                                                <button type="button" class="btn btn-default" id="quxiao" data-dismiss="modal">取消
                                                </button>
                                                {!! csrf_field() !!}
                                                <button type="submit" class="btn btn-success" id="btn-zd"><i
                                                            class="fa fa-check"></i> 保存
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>
	
    <div class="modal fade" id="btn-del" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel1">删除</h4>
                </div>
                <div class="modal-body">
                    <form class="floating-labels role-edit">
                        <input id="id-del" name="id-del" type="hidden" value="">
                        <fieldset style="border:0;">

                            <div class="form-group m-b-40 m-t-10">
                                <p>系统消息</p>
                                <input type="text" class="form-control" id="messgae-del" name="message_del"><span
                                        class="highlight"></span> <span class="bar"></span>

                            </div>
                            <div class="form-actions">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="row">
                                            <div class="col-md-offset-3 col-md-9">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消
                                                </button>
                                                {!! csrf_field() !!}
                                                <button type="submit" class="btn btn-success" id="btn-delete"><i
                                                            class="fa fa-check"></i> 保存
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>	
	
    <div class="panel">
        <div class="panel-wrapper collapse in" aria-expanded="true">
            <div class="panel-body">
                <form action="#">
                    <div class="form-body">
                        <div class="row">

                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label class="control-label">贴子ID</label>
                                    <input type="text" class="column_filter form-control"
                                           data-column="0"
                                           name="id" placeholder="贴子ID">
                                </div>
                            </div>
                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label class="control-label">贴子内容</label>
                                    <input type="text" class="column_filter form-control"
                                           data-column="1"
                                           name="uid" placeholder="贴子内容">
                                </div>
                            </div>
                            <div class="col-xs-3 col-md-6">
                                <div class="form-group">
                                    <label for="status">置顶</label>
                                    <select class="form-control column_filter"
                                            data-column="2">
                                        <option value="">全部</option>
                                        @foreach(App\Carticle::$TopDisplay as $key => $value)
                                            <option value="{{ $key }}">{{ $value }}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="col-xs-3 col-md-6">
                                <div class="form-group">
                                    <label for="status">加精</label>
                                    <select class="form-control column_filter"
                                            data-column="3">
                                        <option value="">全部</option>
                                        @foreach(App\Carticle::$IsexcDisplay as $key => $value)
                                            <option value="{{ $key }}">{{ $value }}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="col-xs-3 col-md-3">
                                <div class="form-group">
                                    <label for="status">发布状态</label>
                                    <select class="form-control column_filter"
                                            data-column="4">
                                        <option value="">全部</option>
                                        @foreach(App\Carticle::$PushDisplay as $key => $value)
                                            <option value="{{ $key }}">{{ $value }}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="panel">
        <div class="panel-heading">贴子列表</div>
        <div class="panel-action" style="margin-top: -9px">
            <a class="btn btn-info" href="{{ url('/quanzi/zxlistPublish') }}">添加贴子</a>
        </div>
        <div class="panel-wrapper collapse in" aria-expanded="true">
            <div class="panel-body">
                <div class="table-responsive">
                    <table id="example23" class="display nowrap" cellspacing="0" width="100%"
                           data-url="{{ url(request()->getUri()) }}">
                        <thead>
                        <tr>
                            <th>ID</th>
							<th>圈子</th>
                            <th>作者名</th>
							<th>内容</th>
                            <th>点赞数</th>
							<th>评论数</th>
							<th>是否加精</th>
                            <th>是否置顶</th>
                            <th>是否删除</th>
                            <th>发表时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
@endsection
@section('js')
    @parent
    <!-- Plugin JavaScript -->
    <script src="{{ asset('plugins/bower_components/moment/moment.js') }}"></script>
    <!-- Date range Plugin JavaScript -->
    <script src="{{ asset('plugins/bower_components/bootstrap-daterangepicker/daterangepicker.js') }}"></script>
    <script src="{{ asset('js/myself.js') }}"></script>
    <script>
        $('.input-daterange-datepicker').daterangepicker({});
    </script>
    <script>
        function hot(sid) { //加精
            $("#id-jj").val(sid);
        }

        function zhiding(sid) { //置顶
			$("#zhiding-modify").val('');
            $("#id-zhiding").val(sid);
        }
		
        function del(sid) {
            $("#id-del").val(sid);
        }
		
        $("#btn-delete").click(function (e) {
            e.preventDefault();
            var id = $("#id-del").val();
            var message = $("#messgae-del").val();
			if(message==''){
				swal('内容不能为空！');
				return false;
			}else{
				swal({
						title: "",
						text: "确定删除吗？",
						type: "warning",
						showCancelButton: true,
						confirmButtonColor: "#DD6B55",
						confirmButtonText: "是的",
						closeOnConfirm: false
					},
					function () {
						$.ajax({
							headers: {
								'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
							},
							url: '/quanzi/listdel/' + id,
							type: 'POST',
							data: {message: message},
							error: function (e) {
								if (e.readyState === 4 && e.status === 422) {
									for (var i in e.responseJSON) {
										if (e.responseJSON[i] !== 'The given data was invalid.') {
											err = e.responseJSON[i];
											for (var j in err) {
												toasterror(err[j][0]);
											}
										}
									}
								}
							},
							success: function (data) {
								if (data.status !== 1) {
									swal(data.message);
								} else {
									swal(data.message, '', 'success');
									$('.confirm').click(function () {
										var _that = $(".hot" + id);
										$(_that).parent().parent().text('');
										location.reload();
									});
								}
							}
						})
					}
				);
			}
        });		
		
		
        //撤销帖子
        obj.on('click', '.btn-chexiao', function () {
            var id = $(this).data('id');
            swal({
                    title: "",
                    text: "确定撤销吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/quanzi/chexiao/' + id,
                        type: 'POST',
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });
		
        obj.on('click', '.btn-jj', function () {
            //复选框
            var id = $(this).data('id');
           // var title = $("#jjtime-modify").val();

            swal({
                    title: "",
                    text: "确定加精吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/quanzi/hot/' + id,
                        type: 'POST',
                        data: {title: ''},
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });

		
        $("#btn-zd").click(function (e) {
            e.preventDefault();
            //复选框
            var id = $("#id-zhiding").val();
            var title = $("#zhiding-modify").val();

			if(title==''){
				swal('标题不能为空！');
				return false;
			}else{
				swal({
						title: "",
						text: "确定要置顶吗？",
						type: "warning",
						showCancelButton: true,
						confirmButtonColor: "#DD6B55",
						confirmButtonText: "是的",
						closeOnConfirm: false
					},
					function () {
						$.ajax({
							headers: {
								'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
							},
							url: '/quanzi/top/' + id,
							type: 'POST',
							data: {title: title},
							error: function (e) {
								if (e.readyState === 4 && e.status === 422) {
									for (var i in e.responseJSON) {
										if (e.responseJSON[i] !== 'The given data was invalid.') {
											err = e.responseJSON[i];
											for (var j in err) {
												toasterror(err[j][0]);
											}
										}
									}
								}
							},
							success: function (data) {
								if (data.status !== 1) {
									swal(data.message);
								} else {
									swal(data.message, '', 'success');
									$('.confirm').click(function () {
										location.reload();
									});
								}
							}
						})
					}
				);
			}
        });
		
		

        //取消加精
        obj.on('click', '.btn-hotoff', function () {
            var id = $(this).data('id');
            swal({
                    title: "",
                    text: "确定取消加精吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/quanzi/hotoff/' + id,
                        type: 'POST',
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });
		

        //取消置顶
        obj.on('click', '.btn-topoff', function () {
            var id = $(this).data('id');
            swal({
                    title: "",
                    text: "确定取消置顶吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/quanzi/topoff/' + id,
                        type: 'POST',
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });

    </script>
@endsection